package com.nanning.system.service.impl;

import com.nanning.system.domain.*;
import com.nanning.system.domain.vo.CarCompleteVo;
import com.nanning.system.domain.vo.CompleteVo;
import com.nanning.system.domain.vo.HeavyCarVo;
import com.nanning.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class BigScreenServiceImpl implements IBigScreenService {

    @Autowired
    private ITaskCompleteService taskCompleteService;
    @Autowired
    private ISendCompleteService sendCompleteService;
    @Autowired
    private IIncomeCompleteService incomeCompleteService;
    @Autowired
    private IHeavyCarService heavyCarService;
    @Autowired
    private IWorkCarService workCarService;
    @Autowired
    private ITodayDataService todayDataService;
    @Autowired
    private ICarCompleteService carCompleteService;

    @Override
    public Map<String, Map<String, BigDecimal>> taskComplete() {
        List<TaskComplete> completeList = taskCompleteService.list();
        return completeList.stream().collect(Collectors.groupingBy(TaskComplete::getType, Collectors.toMap(TaskComplete::getTitle, TaskComplete::getNum)));
    }

    @Override
    public Map<String, Map<String, Map<String, CompleteVo>>> sendComplete() {
        List<SendComplete> sendCompleteList = sendCompleteService.list();
        return sendCompleteList.stream().collect(Collectors.groupingBy(SendComplete::getType,
                Collectors.groupingBy(SendComplete::getTimeRange,
                        Collectors.toMap(SendComplete::getArea, e -> new CompleteVo(e.getRealNum(), e.getPlanNum())))));
    }

    @Override
    public Map<String, Map<String, CompleteVo>> incomeComplete() {
        List<IncomeComplete> completeList = incomeCompleteService.list();
        return completeList.stream().collect(Collectors.groupingBy(IncomeComplete::getTimeRange,
                Collectors.toMap(IncomeComplete::getArea, e -> new CompleteVo(e.getRealNum(), e.getPlanNum()))));
    }

    @Override
    public Map<String, Object> heavyCar() {
        Map<String, Object> result = new HashMap<>();
        List<HeavyCar> heavyCarList = heavyCarService.list();
        Map<String, Object> collect = heavyCarList.stream().collect(Collectors.toMap(HeavyCar::getArea, e -> new HeavyCarVo(e.getInCarNum(), e.getOutCarNum())));
        result.put("在途重车数", collect);
        result.put("卸车能力", heavyCarList.stream().collect(Collectors.toMap(HeavyCar::getArea, HeavyCar::getUnloadCarNum)));
        return result;
    }

    @Override
    public Map<String, Object> workCar() {
        Map<String, Object> result = new HashMap<>();
        List<WorkCar> workCarList = workCarService.list();
        Map<String, Object> collect = workCarList.stream().collect(Collectors.toMap(WorkCar::getArea, e -> new HeavyCarVo(e.getInCarNum(), e.getOutCarNum())));
        result.put("在途重车数", collect);
        result.put("卸车能力", workCarList.stream().collect(Collectors.toMap(WorkCar::getArea, WorkCar::getUnloadCarNum)));
        return result;
    }

    @Override
    public Map<String, Map<String, String>> todayData() {
        List<TodayData> todayDataList = todayDataService.list();
        return todayDataList.stream().collect(Collectors.groupingBy(TodayData::getType, Collectors.toMap(TodayData::getTitle, TodayData::getValue)));
    }

    @Override
    public Map<String, CarCompleteVo> carComplete() {
        List<CarComplete> carCompleteList = carCompleteService.list();
        return carCompleteList.stream().collect(Collectors.toMap(CarComplete::getCategory, e -> new CarCompleteVo(e.getMonthCarNum(), e.getYearCarNum())));
    }
}
